﻿using System;
using System.Configuration;
using mojoPortal.Net;
using mojoPortal.Web;
using System.Text;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
using System.IO;
using Brettle.Web.NeatUpload;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
using Telerik.Web.Design;
using Telerik.Web.UI;
namespace ud_gSDMS.Member
{
    public partial class RelativesAbroad : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;
        private SiteUser _siteUser;
        
        protected String cacheDependencyKey;
        DBQLNS _respository=new DBQLNS();
        
        void Page_Load(object sender, EventArgs e)
        {
            _siteUser = SiteUtils.GetCurrentSiteUser();
            if (_siteUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            }
            
            if (!Page.IsPostBack)
            {
                PopulateLabels();    
                PopulateControls();
                SetupJavaScript();
            }
           
        }
        private void SetupJavaScript()
        {
            
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type='text/javascript' src='/ClientScript/relative.js'></script>");

            if (!Page.ClientScript.IsStartupScriptRegistered(typeof(Page), "loaddata"))
                Page.ClientScript.RegisterStartupScript(typeof(Page), "loadData", sb.ToString());

        }
        private void PopulateLabels()
        {
            leftMenuItem.CurrentSite = Request.RawUrl;
            List<RelativesAbroadd> lst = new List<RelativesAbroadd>();
            RelativesAbroadd ra1 = new RelativesAbroadd("Danh", "Anh em họ", "1-3-1986", "", "Úc", "Việt Nam", "1999");
            RelativesAbroadd ra2 = new RelativesAbroadd("Thanh", "Chú ruột", "24-8-1964", "", "Mỹ", "Việt Nam", "1975");
            lst.Add(ra1);
            lst.Add(ra2);
            Session["Ra"] = lst;
            
          
        }
        private void BindData()
        {
            gvChildInfo.DataSource = Session["Ra"];
            gvChildInfo.DataBind();
            
        }

        private void PopulateControls()
        {
            TextBox abc = new TextBox();
            abc.Text = "test thu";
            
            BindData();
        }
        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
           
        }

       
        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            SuppressPageMenu();
            
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
            cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
        }
        protected void quoctich_Load(object sender, EventArgs e)
        {
            List<quoctichtest> lst = new List<quoctichtest>();
            quoctichtest ra1 = new quoctichtest("1", "Việt Nam");
            quoctichtest ra2 = new quoctichtest("2", "Thái Lan");
            quoctichtest ra3 = new quoctichtest("3", "Indonexia");
            quoctichtest ra4 = new quoctichtest("4", "Lào");
            lst.Add(ra1);
            lst.Add(ra2);
            lst.Add(ra3);
            lst.Add(ra4);
            DropDownList dr = (DropDownList)sender;
              dr.DataValueField = "ID";
              dr.DataTextField = "Name";
              dr.DataSource = lst;
              dr.DataBind();
        }
        private void LoadPanels()
        {

            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion
        DropDownList txt_quoctich;
        protected void gvChildInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            
            gvChildInfo.EditIndex = e.NewEditIndex;
            BindData();
            gvChildInfo.Rows[e.NewEditIndex].Cells[gvChildInfo.Rows[e.NewEditIndex].Cells.Count - 1].CssClass = "gvItem ta_cen div_chucnang test";
            
            
        }

        protected void gvChildInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvChildInfo.EditIndex = -1;
            BindData();
            
        }
        string i;
        protected void gvChildInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DateTime date = new DateTime();

            List<RelativesAbroadd> l = (List<RelativesAbroadd>)Session["Ra"];
            TextBox txt_ten = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt1");
            TextBox txt_quanhe = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt2");
            //TextBox txt_ngaysinh = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt3");
            RadDatePicker txt_ngaysinh = (RadDatePicker)gvChildInfo.Rows[e.RowIndex].FindControl("dat_NgaySinh");
             date = (DateTime)txt_ngaysinh.SelectedDate;
            TextBox txt_nghenghiep = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt4");
            TextBox txt_nuocdinhcu = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt5");
            txt_quoctich = (DropDownList)gvChildInfo.Rows[e.RowIndex].FindControl("drdl_quoctich");
            
            TextBox txt_namdinhcu = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt7");
            RelativesAbroadd newra = new RelativesAbroadd(txt_ten.Text, txt_quanhe.Text, date.ToShortDateString(), txt_nghenghiep.Text, txt_nuocdinhcu.Text, txt_quoctich.SelectedItem.Text , txt_namdinhcu.Text);
            l[e.RowIndex] = newra;
            //l[e.RowIndex] = (RelativesAbroadd)Session[e.RowIndex];
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void quoctich_Change(object sender, EventArgs e)
        {
            DropDownList tam = (DropDownList)sender;
            i = tam.SelectedValue.ToString();
        }

        protected void gvChildInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<RelativesAbroadd> l = (List<RelativesAbroadd>)Session["Ra"];
            l.RemoveAt(e.RowIndex);
            BindData();
        }

        protected void BtnInsert_Click(object sender, EventArgs e)
        {
            if (gvChildInfo.EditIndex == -1)
            {
                List<RelativesAbroadd> l = (List<RelativesAbroadd>)Session["Ra"];
                string date = DateTime.Now.ToShortDateString();
                RelativesAbroadd newinsert = new RelativesAbroadd("", "", date, "", "", "", "");
                l.Add(newinsert);
                gvChildInfo.EditIndex = l.Count - 1;
                BindData();
            }
          //  gvChildInfo.Rows[gvChildInfo.Rows.Count - 1].Cells[7].FindControl
        }
    }

    public class RelativesAbroadd
    {
        public string Ten { get; set; }
        public string QuanHe { get; set; }
        public string NgaySinh { get; set; }
        public string NgheNghiep { get; set; }
        public string NuocDinhCu { get; set; }
        public string QuocTich { get; set; }
        public string NamDinhCu { get; set; }
        public RelativesAbroadd(string ten, string quanhe, string ngaysinh, string nghenghiep, string nuocdinhcu, string quoctich, string namdinhcu)
        {
            this.Ten = ten;
            this.QuanHe = quanhe;
            this.NgaySinh = ngaysinh;
            this.NgheNghiep = nghenghiep;
            this.NuocDinhCu = nuocdinhcu;
            this.QuocTich = quoctich;
            this.NamDinhCu = namdinhcu;

        }
    }
    public class quoctichtest
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public quoctichtest(string ID, string name)
        {
            this.ID = ID;
            this.Name = name;
            ;

        }
    }

    
}